{% extends 'WebProfilerBundle:Profiler:layout.html.twig' %}

{% block toolbar %}
    {% if collector.counterrors %}
        {% set icon %}
            <img width="15" height="28" alt="Logs" src=""/>
            <span class="sf-toolbar-status sf-toolbar-status-yellow">{{ collector.counterrors }}</span>
        {% endset %}
        {% set text %}
            <div class="sf-toolbar-info-piece">
                <b>Exception</b>
                <span class="sf-toolbar-status sf-toolbar-status-yellow">{{ collector.counterrors }}</span>
            </div>
        {% endset %}
        {% include 'WebProfilerBundle:Profiler:toolbar_item.html.twig' with { 'link': profiler_url } %}
    {% endif %}
{% endblock %}

{% block menu %}
<span class="label">
    <span class="icon"><img src="{{ asset('bundles/webprofiler/images/profiler/logger.png') }}" alt="Logger" /></span>
    <strong>Logs</strong>
    {% if collector.counterrors %}
        <span class="count">
            <span>{{ collector.counterrors }}</span>
        </span>
    {% endif %}
</span>
{% endblock %}

{% block panel %}
    <h2>Logs</h2>

    {% set priority = app.request.query.get('priority', 0) %}

    <table>
        <tr>
            <th>Filter</th>
            <td>
                <form id="priority-form" action="" method="get" style="display: inline">
                    <input type="hidden" name="panel" value="logger" />
                    <label for="priority">Priority</label>
                    <select id="priority" name="priority" onchange="document.getElementById('priority-form').submit(); ">
                        {% for value, text in { 100: 'DEBUG', 200: 'INFO', 250: 'NOTICE', 300: 'WARNING', 400: 'ERROR', 500: 'CRITICAL', 550: 'ALERT', 600: 'EMERGENCY' } %}
                        <option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ text }}</option>
                        {% endfor %}
                    </select>
                    <noscript>
                        <input type="submit" value="refresh" />
                    </noscript>
                </form>
            </td>
        </tr>
    </table>

    {% if collector.logs %}
        <ul class="alt">
            {% for log in collector.logs if log.priority >= priority %}
                <li class="{{ cycle(['odd', 'even'], loop.index) }}{% if log.priority >= 400 %} error{% elseif log.priority >= 300 %} warning{% endif %}">
                    {{ log.priorityName }} - {{ log.message }}
                    {% if log.context is defined and log.context is not empty %}
                        <br />
                        <small>
                            <strong>Context</strong>: {{ log.context|yaml_encode }}
                        </small>
                    {% endif %}
                </li>
            {% else %}
                <li><em>No logs available for this priority.</em></li>
            {% endfor %}
        </ul>
    {% else %}
        <p>
            <em>No logs available.</em>
        </p>
    {% endif %}
{% endblock %}
